package com.qf.dao;

import com.qf.pojo.Contractor;
import com.qf.pojo.Developer;
import com.qf.pojo.Project;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName Project
 * @Description TODO
 * @Author Windy
 * @Date 2022/8/25 10:51
 * @Version 1.0
 **/
public interface ProjectDao {

    @Select("select * from Project")
    public List<Project> findAll();



    //查询工程信息及其对应关系的数据
    @Select("select * from project where status=1")
    @Results(id = "allMap",value = {
            @Result(column = "pid",property = "pid"),
            @Result(column = "pname",property = "pname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "did",property = "did"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
//            一对多 （开发商部门）
            @Result(column = "pid",property = "branchs",
                    many = @Many(select = "com.qf.dao.BranchDao.findBranchsAndTaskBypid")
            ),
//            一对多（分项工程）
            @Result(column = "pid",property = "subitems",
                    many = @Many(select = "com.qf.dao.SubitemDao.findSubitemsAndItems")
            ),
//            一对多（工程阶段）
            @Result(column = "pid",property = "stages",
                    many = @Many(select = "com.qf.dao.StageDao.findStageByPid")
            ),
//            一对一（开发商）
            @Result(column = "did",property = "developer",javaType = Developer.class,
                    one = @One(select = "com.qf.dao.DeveloperDao.findDeveloperByDid")
            ),
//            一对一（承建商）
            @Result(column = "did",property = "contractor",javaType = Contractor.class,
                    one = @One(select = "com.qf.dao.ContractorDao.findContractorByCid")
            )
    })
    public List<Project> findOneAndMany();
}
